package cc.togetherit.jcrawler.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolUtil {
    private static ExecutorService executorService = Executors.newFixedThreadPool(50);
    private static ExecutorService singleExecutor = Executors.newSingleThreadExecutor();

    public static void singleExecute(Runnable command) {
        singleExecutor.execute(command);
    }

    public static void execute(Runnable command, boolean withPool, String taskName) {
        if (withPool) {
            executorService.execute(command);
        } else {
            Thread t = new Thread(command);
            t.setName(taskName);
            t.start();
        }
    }

}
